package cn.me.implement.threadpool.v3_0.reject;

import cn.me.implement.threadpool.v3_0.ThreadPool3_0;

/**
 * <h3>拒绝策略的接口</h3>
 * 这里使用了 <strong>策略模式</strong>，将不同的策略作为其子类实现，更换策略时只需要更换策略对象即可
 */
public interface RejectPolicy {

    void reject(ThreadPool3_0 threadPool, Runnable task);

    // 这里创建这几个常量对象，使用时直接传入常量对象即可，无需新建对象，实现对象的复用，好处与单例模式类似
    RejectPolicy THROW_EXCEPTION = new ThrowExceptionPolicy();
    RejectPolicy DISCARD = new DiscardPolicy();
    RejectPolicy DISCARD_OLDEST = new DiscardOldestPolicy();
    RejectPolicy CALLER_RUN = new CallerRunPolicy();
    RejectPolicy NEW_THREAD_RUN = new NewThreadRunPolicy();
}
